<?php
require_once "include/function.php";
connect_db();
class Register
	{
		//ADD Function
		private $username,$password,$address,
		$email,$s_name,$f_name,$title,$sex,$p_code,$pic_type;
			public function setFirstname($f_name)
			{
				$this->f_name=$f_name;
			}
			public function setSurname($s_name)
			{
				$this->s_name=$s_name;
			}
			public function setCode($p_code)
			{
				$this->p_code=$p_code;
			}
			public function setUsername($username)
			{
				$this->username=$username;
			}
			public function setPassword($password)
			{
				$this->password=$password;
			}
			public function setTitle($title)
			{
				$this->title=$title;
			}
			public function setSex($sex)
			{
				$this->sex=$sex;
			}
			public function setEmail($email)
			{
				$this->email=$email;
			}
			public function setAddress($address)
			{
				$this->address=$address;
			}
			public function setPic($pic_type)
			{
				$this->picType=$pic_type;
			}
			public function addRecord()
			{
				$sql="INSERT INTO users (username,password,email,name,surname,title,sex,picture_type) VALUES ('$this->username',md5('$this->password'),'$this->email','$this->f_name','$this->s_name','$this->title','$this->sex','$this->picType')";
				
				
				mysql_query($sql);
				
				$id=mysql_insert_id();
				
				$filename="images/user/". $id . "." . $this->picType;
				move_uploaded_file($_FILES["user_image"]["tmp_name"],$filename);
			}
		public function addProfile()
			{
				$sql="INSERT INTO users (username,password,email,address,name,surname,title,sex,picture_type,personal) VALUES ('$this->username',md5('$this->password'),'$this->email','$this->address','$this->f_name','$this->s_name','$this->title','$this->sex','$this->picType','$this->p_code')";
				mysql_query($sql);
				
				$id=mysql_insert_id();
				
				$filename="images/user/". $id . "." . $this->picType;
				move_uploaded_file($_FILES["user_image"]["tmp_name"],$filename);
			}
			
		public function validateUser()
				{
					$sql="SELECT * FROM users WHERE username='$this->username'";
					$result=mysql_query($sql);
					if(mysql_num_rows($result)>0)
						{
							echo "<font color='red'>Username has already been taken </font>";
						}
					else
						{
							echo "<font color='green'>Username has avalaible </font>";
						}
				}
						
	}
			
